home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Development Kits / HyperCard Related / XCMDs & XFCNs / Byrne's XCMDs&XFCNs / Source / GetSpeakerVol.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-29  |  2.9 KB  |  130 lines  |  [TEXT/MPS ]

  1. /*
  2.     GetSpeakerVol() XFCN v1.1
  3.     
  4.     ©1991 Apple Computer, Inc.; by Mike Byrne
  5.     
  6.     This XFCN takes no parameters.  It simply returns the number of the speaker setting, as it should
  7.     say in the Control Panel.
  8.     
  9.     Form:
  10.     GetSpeakerVol()
  11.     
  12.     # the MPW 3.2 build commands:
  13.     C -b GetSpeakerVol.c -mbg off
  14.         Link -w -t STAK -c WILD -rt XFCN=610 ∂
  15.             -m ENTRYPOINT ∂
  16.             -sg GetSpeakerVol ∂
  17.             GetSpeakerVol.c.o ∂
  18.             "{Libraries}HyperXLib.o" ∂
  19.             "{Libraries}Runtime.o" ∂
  20.             "{Libraries}Interface.o" ∂
  21.             "{CLibraries}StdCLib.o" ∂
  22.             -o "teststack"
  23. */
  24.  
  25. #include <Types.h>
  26. #include <Sound.h>
  27. #include <string.h>
  28. #include <Memory.h>
  29. #include "HyperXCmd.h"
  30.  
  31. #define NULL (long) 0
  32. #define NIL (long) 0
  33.  
  34. #define kNumParams 0
  35.  
  36.  
  37. /* prototypes */
  38. void ErrorBack(XCmdPtr paramPtr, char *message);
  39. void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
  40. void UnlockParams  ( XCmdPtr paramPtr, short paramCount );
  41.  
  42.  
  43.  
  44. pascal void EntryPoint(XCmdPtr paramPtr)
  45. {
  46.     /* variable declarations */
  47.     short    volNum;
  48.     Str255    retString;
  49.  
  50.  
  51.     /* move high and lock the parameters. */
  52.     MoveLockParams(paramPtr, paramPtr->paramCount);
  53.  
  54.     /* check for copyright or syntax help request */
  55.     if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
  56.         ErrorBack(paramPtr, "v1.1, ©1991 Apple Computer, Inc.; by Mike Byrne");
  57.         UnlockParams(paramPtr, paramPtr->paramCount);
  58.         return;
  59.     } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
  60.         ErrorBack(paramPtr, "GetSpeakerVol syntax is 'GetSpeakerVol()'");
  61.         UnlockParams(paramPtr, paramPtr->paramCount);
  62.         return;
  63.     }
  64.  
  65.     /* not a copyright or help request.       */     
  66.     /* check for correct number of parameters */
  67.     if (paramPtr->paramCount != kNumParams) {
  68.         ErrorBack(paramPtr, "Error: GetSpeakerVol syntax is 'GetSpeakerVol()'");
  69.         UnlockParams(paramPtr, paramPtr->paramCount);
  70.         return;
  71.     }
  72.  
  73.     /* okay, now the meat.  Send in the call. */
  74.     GetSoundVol(&volNum);
  75.     NumToString( (long) volNum, retString);
  76.     p2cstr(retString);
  77.     ErrorBack(paramPtr, retString);
  78.     return;
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.     
  87. /* allocate and load up paramPtr->returnValue with a string 
  88.    -------------------------------------------------------- */
  89. void ErrorBack(XCmdPtr paramPtr, char *message)
  90. {
  91.     Handle  mesHnd;
  92.  
  93.     /*
  94.         Allocate space for an error message.
  95.         Copy the string into it.
  96.         Return the handle to HyperCard.
  97.     */
  98.     mesHnd = NewHandle((long)(strlen(message)+1));
  99.     if (mesHnd == nil) return;
  100.     strcpy((char *)*mesHnd,message);
  101.     paramPtr->returnValue = mesHnd;
  102. }
  103.  
  104.  
  105.  
  106. /*  move high and lock down all parameters  
  107.     ----------------------------------------------------------------------- */
  108. void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
  109. {
  110.     short i;
  111.     
  112.     for(i=0; i <= paramCount-1; i++)
  113.     {
  114.         MoveHHi(paramPtr->params[i]);
  115.         HLock(paramPtr->params[i]);
  116.     }
  117. }
  118.  
  119.  
  120.  
  121.  
  122. /* unlock all parameter handles in the XCmdBlock  
  123.    ---------------------------------------------  */
  124. void UnlockParams  ( XCmdPtr paramPtr, short paramCount )
  125. {    short i;
  126.     
  127.     for(i=0; i <= paramCount-1; i++)
  128.         { HUnlock(paramPtr->params[i]);}
  129. }
  130.